# Contributor: Olliver Schinagl <oliver@schinagl.nl>
# Maintainer: Olliver Schinagl <oliver@schinagl.nl>
pkgname="cpuburn"
pkgver="1.4a_git20160316"
pkgrel=0
pkgdesc="Suite of CPU burn utitilies"
url="http://ssvb.github.io/2012/04/10/cpuburn-arm-cortex-a9.html https://web.archive.org/web/20110623074500/pages.sbcglobal.net/redelm/"
arch="aarch64 armhf armv7 x86 x86_64"
license="MIT"
options="!check textrels" # No checks available
_githash="ad7e646700d14b81413297bda02fb7fe96613c3f"
source="
	https://github.com/ssvb/cpuburn-arm/archive/${_githash}.zip
	cpuburn_1_4a.tar.gz::https://dev.gentoo.org/~conikost/files/cpuburn_1_4a_tar.gz
	cpuburn-1.4a-variables.patch
"
builddir="${srcdir}/cpuburn-1.4a"

build() {
	cd "${srcdir}/cpuburn-arm-${_githash}"
	case "${CARCH}" in
	armhf|armv7)
		gcc -o "cpuburn-a7" "cpuburn-a7.S"
		gcc -o "cpuburn-a8" "cpuburn-a8.S"
		gcc -o "cpuburn-a9" "cpuburn-a9.S"
		gcc -o "cpuburn-a53" "cpuburn-a53.S"
		gcc -o "cpuburn-krait" "cpuburn-krait.S"
		;;
	aarch64)
		gcc -o "cpuburn-a53" "cpuburn-a53.S"
		;;
	esac

	cd "${srcdir}/cpuburn-1.4a"
	sed -i -e 's|gcc -s|$(CC) $(CFLAGS) -m32 $(LDFLAGS)|' Makefile
	case "${CARCH}" in
	x86|x86_64)
		make
		;;
	esac
}

package() {
	case "${CARCH}" in
	armhf|armv7)
		install -D -m 0755 "${srcdir}/cpuburn-arm-${_githash}/cpuburn-a7" \
		        "${pkgdir}/usr/bin/cpuburn-a7"
		install -D -m 0755 "${srcdir}/cpuburn-arm-${_githash}/cpuburn-a8" \
		        "${pkgdir}/usr/bin/cpuburn-a8"
		install -D -m 0755 "${srcdir}/cpuburn-arm-${_githash}/cpuburn-a9" \
		        "${pkgdir}/usr/bin/cpuburn-a9"
		install -D -m 0755 "${srcdir}/cpuburn-arm-${_githash}/cpuburn-a53" \
		        "${pkgdir}/usr/bin/cpuburn-a53"
		install -D -m 0755 "${srcdir}/cpuburn-arm-${_githash}/cpuburn-krait" \
		        "${pkgdir}/usr/bin/cpuburn-krait"
		;;
	aarch64)
		install -D -m 0755 "${srcdir}/cpuburn-arm-${_githash}/cpuburn-a53" \
		        "${pkgdir}/usr/bin/cpuburn-a53"
		;;
	x86|x86_64)
		for _bin in "${srcdir}/cpuburn-1.4a/"*; do
			if [ ! -f "${_bin}" ] || [ ! -x "${_bin}" ]; then
				continue
			fi
			install -D -m 0755 "${_bin}" \
			        "${pkgdir}/usr/bin/${_bin##*/}"
		done
		;;
	esac
}

sha512sums="
101775ac456c3cb49256e96ebac483568b59a5260c07bfae94800a5f0872a395dbae81ab9cc81ace75e827fe0c16c60b3f2dd8ae85b3c8067b34c3da792a8162  ad7e646700d14b81413297bda02fb7fe96613c3f.zip
db84cabe70af0b6b3579c746f6df08c268b7145c9521fc609ce5b4cfd497dbb0639e52ab55f34110cff297ec23cf1413db28c6bff4e6f81a69722626886df7ce  cpuburn_1_4a.tar.gz
eef2f5dfc3a49712568001a273be117126beac27560b6e4386e89893ef30acda76c956b96a9a86bf1a0a424003f3eb9214a8a4a1c828fcbbf809eed82a5a7af7  cpuburn-1.4a-variables.patch
"
